package com.nf.health.app.intervention_details.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 恩福 on 2016/11/10.
 * 个人健康信息汇总 Adapter
 *
 * @auther changpeng
 * @email obj_cp@126.com
 */

public class CatalogueDetailsAdapter extends RecyclerView.Adapter {
    private static final int TYPE_HEAD = 0;
    private static final int TYPE_CATALOGUE = 1;

    private static final int TYPE_FOOTER = 13;

    private Context mContext;

    public CatalogueDetailsAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case TYPE_HEAD:
                view = LayoutInflater.from(mContext).inflate(R.layout.catalogue_contents, parent, false);
                return new CatalogueContentsHolder(view);
            case TYPE_CATALOGUE:
                view = LayoutInflater.from(mContext).inflate(R.layout.item_catalogue, parent, false);
                return new CatalogueHolder(view);
            case TYPE_FOOTER:
                view = LayoutInflater.from(mContext).inflate(R.layout.scheme_common_head_info, parent, false);
                return new FooterHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof CatalogueHolder) {
            CatalogueHolder catalogueHolder = (CatalogueHolder) holder;
            switch (position){
                case 1:catalogueHolder.tvTitle.setText("个人健康信息汇总\nSummary of personal health information");
                    break;
                case 2:catalogueHolder.tvTitle.setText("健康行动改善指南\nGuide to improving health action");
                    break;
                case 3:catalogueHolder.tvTitle.setText("膳食方案\nMeal plan");
                    break;
                case 4:catalogueHolder.tvTitle.setText("运动方案\nMotion scheme");
                    break;
                case 5:catalogueHolder.tvTitle.setText("音乐方案\nMusic program");
                    break;
                case 6:catalogueHolder.tvTitle.setText("经络方案\nMeridian project");
                    break;
                case 7:catalogueHolder.tvTitle.setText("监测计划\nMonitoring plan");
                    break;
//                case 8:catalogueHolder.tvTitle.setText("调理处方\nConditioning prescription");
//                    break;
                case 8:catalogueHolder.tvTitle.setText("医嘱\nDoctor's advice");
                    break;

            }
            if (position < 10) {
                catalogueHolder.tvNum.setText("0" + position);
            } else {
                catalogueHolder.tvNum.setText("" + position);
            }
        }

        if (holder instanceof FooterHolder) {
            FooterHolder footerHolder = (FooterHolder) holder;
            footerHolder.tvSchemeCommonHeadTitle.setText("重要信息");
            footerHolder.tvSchemeCommonHeadContent.setText("本方案很重要，请认真执行");
        }

    }

    @Override
    public int getItemCount() {
        return 10;
    }

    @Override
    public int getItemViewType(int position) {
        switch (position) {
            case 0:
                return TYPE_HEAD;
            case 9:
                return TYPE_FOOTER;
        }
        return TYPE_CATALOGUE;
//        return super.getItemViewType(position);
    }

    class CatalogueContentsHolder extends RecyclerView.ViewHolder {

        public CatalogueContentsHolder(View itemView) {
            super(itemView);
        }
    }

    class CatalogueHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_num)
        TextView tvNum;
        @Bind(R.id.tv_title)
        TextView tvTitle;

        public CatalogueHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class FooterHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_scheme_common_head_title)
        TextView tvSchemeCommonHeadTitle;
        @Bind(R.id.tv_scheme_common_head_content)
        TextView tvSchemeCommonHeadContent;

        public FooterHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
